﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class FillCustomerInfo : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (IsPostBack)
            return;
        DTO.NguoiDungDto user = (DTO.NguoiDungDto)Session["user"];
        if (user != null)
        {
            txtCustomerName.Text = user.HoTen;
            txtAddress.Text = user.DiaChi;
            txtPhoneNumber.Text = user.DienThoai;
            txtEmail.Text = user.Email;
        }
    }
    protected void btnPrevious_Click(object sender, EventArgs e)
    {
        Response.Redirect("Cart.aspx");
    }
    protected void btnContDatHang_Click(object sender, EventArgs e)
    {
        Response.Redirect("Default.aspx");
    }
    protected void btnSubmit_Click(object sender, EventArgs e)
    {
        if (txtCustomerName.Text == "")
        {
            lblCustomerNameErr.Text = "<span class='invalidMessage'>Bạn chưa nhập tên</span>";
            lblPhoneNumberErr.Text = "";
            lblAddressErr.Text = "";
            return;
        }
        if (txtAddress.Text == "")
        {
            lblCustomerNameErr.Text = "";
            lblPhoneNumberErr.Text = "";
            lblAddressErr.Text = "<span class='invalidMessage'>Bạn chưa nhập địa chỉ</span>";
            return;
        }
        if (txtPhoneNumber.Text == "")
        {
            lblCustomerNameErr.Text = "";
            lblAddressErr.Text = "";
            lblPhoneNumberErr.Text = "<span class='invalidMessage'>Bạn chưa nhập điện thoại</span>";
            return;
        }

        DTO.GioHangDto GioHang = (DTO.GioHangDto)Session["GioHang"];
        if (GioHang == null)
            Response.Redirect("Cart.aspx");
        GioHang.HoTen = txtCustomerName.Text;
        GioHang.DiaChi = txtAddress.Text;
        GioHang.DienThoai = txtPhoneNumber.Text;
        GioHang.Email = txtEmail.Text;
        GioHang.KieuThanhToan = Int16.Parse(DropDownList1.SelectedValue);
        bool result = BUS.HoaDonBus.ThemHoaDon(GioHang);
        if (result == false)
            Response.Redirect("KetQuaDatHang.aspx?failed=1");
        Response.Redirect("KetQuaDatHang.aspx?success=1");
    }
}
